const express = require('express'),
    bodyParser = require('body-parser'),
    proxy = require('express-http-proxy'),
    config = require('./config'),
    _ = require('lodash')

const app = express(),
    getIPAdress = require('./src/utils').getIPAdress,
    proxyPath = config.proxyPath,
    port = config.port || 3030,
    ignoreList = config.ignoreList

const mockApi = require('./src/mockApi')

app.use(bodyParser.urlencoded({ extended: false })) // 请求参数格式化
app.use(bodyParser.json()) // 请求参数格式化
app.use(function (req, res, next) {
    res.set({
        'Cache-Control': 'no-cache, no-store, must-revalidate' // 强制不使用缓存
    })
    next()
})

// 模拟数据
mockApi(app)

// 请求转发
if (proxyPath) {
    app.use('/', proxy(proxyPath))
}

const server = app.listen(port, getIPAdress(), function () {
    var host = server.address().address
    var port = server.address().port

    console.log('App listening at http://%s:%s', host, port)
})
